//
//  BkFaceDetailHeader.m
//  TuDianEducation
//
//  Created by lixinkeji on 2021/1/12.
//  Copyright © 2021 zhangbenchao. All rights reserved.
//

#import "BkFaceDetailHeader.h"
#import "LXSaveUserInforTool.h"

@interface BkFaceDetailHeader(){
    CGFloat imgTop;
}

@property (nonatomic, strong) UIImageView *headerImg;
@property (nonatomic, strong) UILabel *nameLabel;

@property (nonatomic, strong) UILabel *dateLable;
@property (nonatomic,strong) UILabel *contentLable;

@property (nonatomic,strong) NSMutableArray *imgUiarray;
@property (nonatomic,strong) NSArray*imgArray;

@property (nonatomic,strong) UILabel *oldLabel;
@property (nonatomic,strong) UIButton *commentsBtn;
@property (nonatomic,strong) UIButton *likesBtn;

@end

@implementation BkFaceDetailHeader

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.frame = CGRectMake(0, 0, TSScreenWidth, TSScaleW(200));
        [self addSubview:self.headerImg];
        [self addSubview:self.nameLabel];
        [self addSubview:self.dateLable];
        [self addSubview:self.contentLable];
         self.imgArray = @[@"",@"",@"",@""];

        [self addSubview:self.commentsBtn];
        [self addSubview:self.likesBtn];
        self.height = self.likesBtn.bottom + TSScaleW(20);
        self.backgroundColor = kWhiteColor;
    }
    return self;
}



-(UIImageView *)headerImg{
    if (!_headerImg) {
        _headerImg = [[UIImageView alloc]initWithFrame:CGRectMake(TSScaleW(11), TSScaleW(15), TSScaleW(35), TSScaleW(35))];
        [_headerImg setCornerRadius:_headerImg.height/2.f];
        _headerImg.backgroundColor = kGrayTxtColor;
 
    }
    return _headerImg;
}
-(UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [TSWLTools allocLabel:@"首届星洲" font:systemBoldFont(TSScaleW(13)) textColor:kMainTxtColor frame:CGRectMake(_headerImg.right + TSScaleW(11), _headerImg.top + TSScaleW(12), TSScaleW(300), TSScaleW(13)) textAlignment:(NSTextAlignmentLeft)];
    }
    return _nameLabel;
}


-(UILabel *)dateLable{
    if (!_dateLable) {
        _dateLable = [TSWLTools allocLabel:@"1天前" font:systemFont(TSScaleW(11)) textColor:kGreenColor frame:CGRectMake(_nameLabel.left, _nameLabel.top, _nameLabel.width,TSScaleW(11)) textAlignment:(NSTextAlignmentRight)];
        
       
    }
    return _dateLable;
}
-(UILabel *)contentLable{
    if (!_contentLable) {
        _contentLable = [TSWLTools allocLabel:@"一次很好的购物体验，服务周到，物流快速，配送也很周到，卖家态度也很好~ 下次还回购~" font:systemFont(TSScaleW(12)) textColor:kMainTxtColor frame:CGRectMake(TSScaleW(10), TSScaleW(11) + _headerImg.bottom, TSScaleW(355), TSScaleW(42)) textAlignment:(NSTextAlignmentLeft)];
        _contentLable.numberOfLines = 0;
    }
    return _contentLable;
}

-(NSMutableArray *)imgUiarray{
    if (!_imgUiarray) {
        _imgUiarray = [NSMutableArray array];
    }
    return _imgUiarray;
}
-(void)setImgArray:(NSArray *)imgArray{
    _imgArray = imgArray;
    for (UIView *v in self.imgUiarray) {
        [v removeFromSuperview];
    }
    [self.imgUiarray removeAllObjects];
    imgTop = _contentLable.bottom + TSScaleW(18);
    for (int i = 0; i < _imgArray.count; i ++) {
        UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(TSScaleW(12) , imgTop, TSScaleW(200), TSScaleW(200))];
        img.backgroundColor = kGrayBtnBacColor;
        [img sd_setImageWithURL:[NSURL URLWithString:imgArray[i]]];
        
        [self.imgUiarray addObject:img];
        imgTop +=img.height + 5;
        [self addSubview:img];
        img.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
        [img addGestureRecognizer:tap];
    }
    
}




-(void)tapAction:(UITapGestureRecognizer *)tap{
NSInteger index = [self.imgUiarray indexOfObject:tap.view];
[TSWLTools pictureSelectWithPicArr:self.imgArray withIndex:index];
}

-(UIButton *)commentsBtn{
    if (!_commentsBtn) {
        _commentsBtn = [TSWLTools allocButtonTitle:@"99" font:systemFont(TSScaleW(12)) textColor:kGrayTxtColor image:[UIImage imageNamed:@"pingun"] frame:CGRectMake(0, TSScaleW(14) + imgTop, TSScaleW(60), TSScaleW(30)) sel:@selector(commentsBtnAction) taget:self];
        [_commentsBtn setImageEdgeInsets:UIEdgeInsetsMake(0, -TSScaleW(5), 0, 0)];
        _commentsBtn.left = 0;
    }
    return _commentsBtn;
}
-(void)commentsBtnAction
{
    
}
-(UIButton *)likesBtn{
    if (!_likesBtn) {
        _likesBtn = [TSWLTools allocButtonTitle:@"99" font:systemFont(TSScaleW(12)) textColor:kGrayTxtColor image:[UIImage imageNamed:@"点赞_d"] frame:CGRectMake(_commentsBtn.right, _commentsBtn.top, TSScaleW(60), TSScaleW(30)) sel:@selector(likesBtnAction:) taget:self];
        [_likesBtn setImageEdgeInsets:UIEdgeInsetsMake(0, -TSScaleW(5), 0, 0)];
        [_likesBtn setImage:[[UIImage imageNamed:@"点赞_d"] imageChangeColor:kRedColor] forState:(UIControlStateSelected)];
    }
    return _likesBtn;
}
-(void)likesBtnAction:(UIButton *)sender
{
    !self.dianzanBlock?:self.dianzanBlock(sender);
}
-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    [_headerImg sd_setImageWithURL:[NSURL URLWithString:_dataDic[@"usericon"]]];
    _nameLabel.text = _dataDic[@"username"];
    _dateLable.text = _dataDic[@"adtime"];
    _contentLable.text = _dataDic[@"content"];
    self.imgArray = _dataDic[@"images"];
//    "collectCount":"",//收藏数量
//                "shareCount":"",//分享数量
//                "commentCount":"",//评论数量
    [self.commentsBtn setTitle:_dataDic[@"commentnum"] forState:(UIControlStateNormal)];
   // [self.shareBtn setTitle:_dataDic[@"shareCount"] forState:(UIControlStateNormal)];
    [self.likesBtn setTitle:_dataDic[@"zannum"] forState:(UIControlStateNormal)];
  
    [self addSubview:self.commentsBtn];
    self.commentsBtn.top = TSScaleW(14) + imgTop;
    self.likesBtn.top = TSScaleW(14) + imgTop;
    self.height = self.likesBtn.bottom + TSScaleW(20);
    !self.reloadFrameBlock?:self.reloadFrameBlock();
    NSString *iszan = self.dataDic[@"iszan"];
    self.likesBtn.selected =iszan.intValue;
}

@end
